package com.tengfei.api.user;

import com.tengfei.common.annotation.Anonymous;
import com.tengfei.common.core.controller.BaseController;
import com.tengfei.common.core.domain.PageQuery;
import com.tengfei.common.core.domain.R;
import com.tengfei.common.core.page.TableDataInfo;
import com.tengfei.main.user.domain.SearchEntity;
import com.tengfei.main.user.domain.bo.quBank.UserQuAnsBo;
import com.tengfei.main.user.domain.vo.quBank.*;
import com.tengfei.main.user.service.IUserQuBankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author feige
 * @version v1.0
 * @date 2022-08-15-21:14
 * @description 用户题库控制器
 */

@Validated
@RestController
@Api(value = "用户题库控制器", tags = {"用户题库模块"})
@RequestMapping("/user/quBank")
public class UserQuBankController extends BaseController {

    @Resource
    private IUserQuBankService quBankService;

    /**
     * 查询公开题库列表
     */
    @Anonymous
    @GetMapping("/list/pub")
    @ApiOperation("查询公开题库列表")
    public R<TableDataInfo<UserQuBankVo>> qbBankList(SearchEntity search, PageQuery pageQuery) {
        return R.ok(quBankService.quBankList(search, pageQuery));
    }

    /**
     * 查询用户个人题库列表
     */
    @GetMapping("/list")
    @ApiOperation("查询用户个人题库列表")
    public R<List<UserQuBankVo>> userQbBankList() {
        return R.ok(quBankService.userQuBankList());
    }

    /**
     * 查询客观题目详细信息(含答案)
     */
    @GetMapping("/objQu/{objId}")
    @ApiOperation("查询客观题目信息(含答案)")
    public R<UserObjVo> objInfo(@ApiParam("客观题目id") @NotNull(message = "客观题目id不能为空")
                                @PathVariable("objId") Long objId) {
        return R.ok(quBankService.objQuById(objId));
    }

    /**
     * 查询主观题目详细信息(含答案)
     */
    @GetMapping("/subQu/{subId}")
    @ApiOperation("查询主观题目信息(含答案)")
    public R<UserSubVo> subInfo(@ApiParam("主观题目id") @NotNull(message = "主观题目id不能为空")
                                @PathVariable("subId") Long subId) {
        return R.ok(quBankService.subQuById(subId));
    }

    /**
     * 查询题库题目列表
     */
    @GetMapping("/qu/list")
    @ApiOperation("查询题库题目列表")
    public R<List<UserQbQuVo>> qbQuList(@ApiParam("题库id") @NotNull(message = "题库id不能为空")
                                        @RequestParam("qbId") Long qbId) {
        return R.ok(quBankService.qbQuList(qbId));
    }

    /**
     * 查询题目详细信息
     */
    @GetMapping("/quInfo")
    @ApiOperation("查询题目详细信息")
    public R<Object> quInfo(@ApiParam("题目id") @NotNull(message = "题目id不能为空")
                            @RequestParam("quId") Long quId,
                            @ApiParam("题目类型") @NotNull(message = "题目类型不能为空")
                            @RequestParam("quType") Integer quType) {
        return quBankService.quInfo(quId, quType);
    }

    /**
     * 上传/修改题目信息
     */
    @PostMapping("/upload/quAns")
    @ApiOperation("上传/修改题目答案信息")
    public R<Void> uploadQuAns(@Validated @RequestBody UserQuAnsBo bo) {
        return toAjax(quBankService.uploadQuAns(bo));
    }


    /**
     * 查询用户已答题目答案信息
     */
    @GetMapping("/quAns/{id}")
    @ApiOperation("查询用户已答题目答案信息")
    public R<UserQuAnsVo> userQuAns(@ApiParam("id") @NotNull(message = "id不能为空")
                                    @PathVariable("id") Long id) {
        return R.ok(quBankService.getUserQuAns(id));
    }

    /**
     * 查询用户题库已答题目答案列表信息
     */
    @GetMapping("/quAns/List")
    @ApiOperation("查询用户题库已答题目答案列表信息")
    public R<List<UserQuAnsVo>> userQuAnsList(@ApiParam("qbId") @NotNull(message = "题库id不能为空")
                                          @RequestParam("qbId") Long qbId) {
        return R.ok(quBankService.getUserQuAnsList(qbId));
    }


}
